package cn.kgc.vue.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.kgc.vue.common.ResponseResult;
import cn.kgc.vue.common.ResponseStatus;
import cn.kgc.vue.dto.SchedulePageDTO;
import cn.kgc.vue.entity.Schedule;
import cn.kgc.vue.mapper.ScheduleMapper;
import cn.kgc.vue.service.ScheduleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;


@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule>  implements ScheduleService{

    @Resource
    private ScheduleMapper scheduleMapper;

    @Override
    public ResponseResult getPage(SchedulePageDTO schedulePageDTO) {
        LambdaQueryWrapper<Schedule> lambda = new QueryWrapper<Schedule>().lambda();
        lambda.eq(ObjectUtil.isNotNull(schedulePageDTO.getClassTime()),Schedule::getClassTime,schedulePageDTO.getClassTime());

        Page<Schedule> schedulePage = new Page<>(schedulePageDTO.getCurrentPage(), schedulePageDTO.getLimit());
        scheduleMapper.selectPage(schedulePage, lambda);

        ResponseResult responseResult = new ResponseResult();
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",schedulePage.getTotal());
        map.put("currentPageData",schedulePage.getRecords());
        responseResult.success(ResponseStatus.SUCCESS,map);

        return responseResult;
    }
}




